/**
 *	api目录下的控制器，即时通讯REIM
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framework.Controller.api;



import com.framerock.server.Response;
import com.framerock.baselib.CDate;
import com.framerock.baselib.Json;
import com.framework.Flow.Flow;

import com.framework.Model.ModelReim;



public class ControllerReim extends ControllerApi  {



    protected String runAction(String action)
    {
        if(action.equals("history"))return this.history();
        if(action.equals("historydel"))return this.historydel();
        if(action.equals("creategroup"))return this.creategroup();
        if(action.equals("groupexit"))return this.groupexit();
        if(action.equals("groupedit"))return this.groupedit();
        if(action.equals("cehui"))return this.cehui();
        return super.runAction(action);
    }


    /**
     * 进入会话获取数据
     * */
    public String data()
    {
        Flow flow    = Flow.get(this.nDb, "immess", mRequest);
        String data  = flow.action("chatdata","");
        return Response.returnSuccess(data);
    }

    /**
     * 提交数据发消息
     * */
    public String submit()
    {
        Flow flow    = Flow.get(this.nDb, "immess", mRequest);
        String data  = flow.action("sendchat","");
        return Response.returnSuccess(data);
    }

    /**
     * 撤回
     * */
    private String cehui()
    {
        Flow flow    = Flow.get(this.nDb, "immess", mRequest);
        String data  = flow.action("cehui","");
        return Response.returnSuccess(data);
    }

    /**
     * 读取历史记录
     * */
    public String history()
    {
        Json json     = new Json();
        ModelReim obj = new ModelReim(this.nDb);
        obj.setRequest(mRequest);
        json.putVal("historyarr", obj.getHistory(mRequest.get("lastdt")));
        json.putVal("nowdt", CDate.now());
        return Response.returnSuccess(json.getJson());
    }

    /**
     * 删除历史记录
     * */
    public String historydel()
    {
        int type = mRequest.getInt("type");
        int id   = mRequest.getInt("id");
        ModelReim obj = new ModelReim(this.nDb);
        obj.delHistory(type, mRequest.USEAID, id);
        return Response.returnSuccess();
    }

    /**
     * 创建群组
     * */
    public String creategroup()
    {
        Flow flow    = Flow.get(this.nDb, "immess", mRequest);
        String data  = flow.action("creategroup","");
        return Response.returnSuccess(data);
    }

    /**
     * 退出群
     * */
    public String groupexit()
    {
        int type    = mRequest.getInt("type");
        int gid     = mRequest.getInt("gid");
        String sid  = mRequest.get("sid");

        ModelReim obj = new ModelReim(this.nDb);
        obj.exitGroup(type, gid, sid);
        return Response.returnSuccess();
    }

    /**
     * 修改群信息
     * */
    public String groupedit()
    {
        Flow flow    = Flow.get(this.nDb, "imgroup", mRequest);
        String data  = flow.action("groupedit","");
        return Response.returnSuccess(data);
    }

}
